<%--
  Created by IntelliJ IDEA.
  User: LENOVO
  Date: 2021/6/4
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<html>
<head>
    <title>211806398陆桂莺</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style type="text/css">
        .bg{
            padding-top: 200px;
            background-image: url(img/bg.png);
            position: fixed;
            height: 1000px;
            width: 1536px;
        }
        .btn{
            margin-top: 30px;
        }
    </style>
</head>
<body>
    <div class="bg" align="center">
        <div class="panel panel-success" style="width: 650px;border-radius: 20px;">
            <div class="panel-heading" style="border-radius: 20px 20px 0px 0px;">
                <h2 class="" style="font-weight: 600;">通用周报管理平台</h2>
            </div>
            <div class="panel-body" style="height: 300px;padding: 70px 50px;font-size: 20px;">
                <form class="form-horizontal" role="form" align="center" id="loginForm" action="/dailyreport">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="uname" placeholder="请输入用户名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="upass" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-10">
                            <input type="password" class="form-control" id="upass" placeholder="请输入密码">
                        </div>
                    </div>
                    <input onclick="login()" type="button" class="btn btn-success btn-lg btn-block" value="登录"></input>
                </form>
                <a href="/dailyreport/user/user">注册</a>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">
    function login() {
        var username=$("#uname").val();
        var password=$("#upass").val();
        if(username == "" || password == ""){
            alert("用户名和密码不能为空！");
        }
        else {
            $.ajax({
                url:"/dailyreport/user/login",
                data:{"username":username,"password":password},
                dataType:"json",
                success:function (data) {
                    if(data.code=="1"){
                        alert("登陆成功");
                        //通过加密解决中文乱码
                        var codeName = encodeURI(username);
                        window.location.href="/dailyreport/report/back?username=" + codeName;
                    }
                    else{
                        alert("登陆失败");
                    }
                }
            });
        }
    }
</script>
</html>
